using Godot;
using System;
using Timer = Godot.Timer;

public partial class DifficultyManager : Node
{
    [Signal]
    public delegate void StopSpawningEnemiesEventHandler();

    /// <summary>
    /// 游戏时间长度
    /// </summary>
    [Export] public float ExGameLength = 10.0f;

    // 制作敌人出现时间曲线
    [Export] public Curve ExSpawnTimeCurve;

    // 制作敌人生命值变化曲线
    [Export] public Curve ExEnemyHealthCurve;
    private Timer _timer;

// 重写_Ready()方法
    public override void _Ready()
    {
        // 获取Timer节点
        _timer = GetNode<Timer>("Timer");
        // 开始计时器，计时时间为ExGameLength
        _timer.Start(ExGameLength);
        // 设置游戏速度
        // Engine.TimeScale = 4;
    }

    public override void _Process(double delta)
    {
        // GD.Print(GetSpawnTime());
    }

    public float GameProgressRatio()
    {
        return 1.0f - ((float)_timer.TimeLeft / ExGameLength);
    }

    /// <summary>
    /// 获取敌人出现时间
    /// </summary>
    /// <returns></returns>
    public float GetSpawnTime()
    {
        // 返回沿曲线存在于X位置偏移处的点的Y值
        return ExSpawnTimeCurve.Sample(GameProgressRatio());
    }

    /// <summary>
    /// 获取敌人生命值
    /// </summary>
    /// <returns></returns>
    public int GetEnemyHealth()
    {
        // 返回沿曲线存在于X位置偏移处的点的Y值
        return (int)Math.Round(ExEnemyHealthCurve.Sample(GameProgressRatio()));
    }

    public void OnTimerTimeout()
    {
        GD.Print("触发OnTimerTimeout事件！");
        // 发送自定义信号
        EmitSignal(SignalName.StopSpawningEnemies);
    }
}